package com.kexun;

import cn.hutool.core.io.file.FileReader;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.List;

public class Douyin {

    public static void main(String[] args) throws AWTException, InterruptedException {
        Robot robot = new Robot();
        System.out.println("评论框坐标");
        Thread.sleep(5000);
        Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
        System.out.println("Mouse at x: " + mouseLocation.x + ", y: " + mouseLocation.y);
        int x = mouseLocation.x;
        int y = mouseLocation.y;

        System.out.println("点赞坐标");
        Thread.sleep(5000);
        Point mouseLocation1 = MouseInfo.getPointerInfo().getLocation();
        int x1 = mouseLocation1.x;
        int y1 = mouseLocation1.y;
        System.out.println("Mouse at x: " + x1 + ", y: " + y1);


        FileReader fileReader = new FileReader(args[0]);
        List<String> strings = fileReader.readLines();
        for (String string : strings) {
            Thread.sleep(2000);
            Color color = robot.getPixelColor(x1, y1);
            System.out.println("坐标(" + x1 + ", " + y1 + ")的颜色为：RGB(" + color.getRed() + ", "
                    + color.getGreen() + ", " + color.getBlue() + ")");
            if (color.getRed() == 255 && color.getGreen() == 255 && color.getGreen() == 255) {
                System.out.println("观看视频");
                //观看5s
                Thread.sleep(30000);

                Toolkit toolkit = Toolkit.getDefaultToolkit();
                Clipboard clipboard = toolkit.getSystemClipboard();
                clipboard.setContents(new StringSelection(string), null);
                //移动鼠标
                System.out.println("点击评论框");
                robot.mouseMove(x, y);
                robot.mousePress(InputEvent.BUTTON1_MASK);
                robot.mouseRelease(InputEvent.BUTTON1_MASK);
                Thread.sleep(1000);
                System.out.println("粘贴文案:" + string);

                //ctrl+v
//            robot.keyPress(KeyEvent.VK_META);
                robot.keyPress(KeyEvent.VK_CONTROL);
                robot.keyPress(KeyEvent.VK_V);

//            robot.keyRelease(KeyEvent.VK_META);
                robot.keyRelease(KeyEvent.VK_CONTROL);
                robot.keyRelease(KeyEvent.VK_V);
                Thread.sleep(1000);

                System.out.println("发送");
                //回车发送
                robot.keyPress(KeyEvent.VK_ENTER);
                robot.keyRelease(KeyEvent.VK_ENTER);
                Thread.sleep(30000);//流5s转发
                System.out.println("点赞");
                //点赞
                robot.mouseMove(x1, y1);
                robot.mousePress(InputEvent.BUTTON1_MASK);
                robot.mouseRelease(InputEvent.BUTTON1_MASK);

            }
            Thread.sleep(2000);
            //把鼠标拿开
            robot.mouseMove(x1 - 200, y1 - 300);
            System.out.println("下一个视频");
            //下一个
            robot.keyPress(KeyEvent.VK_DOWN);
            robot.keyRelease(KeyEvent.VK_DOWN);


        }


    }

}
